import java.util.*;

/**
 * @author LKQ
 * @date 2022/6/6 22:24
 * @description 暴力
 */
public class Solution {
    public static void main(String[] args) {
        Solution solution = new Solution();
        solution.maxFreq("aababcaab", 2, 3, 4);
    }
    public int maxFreq(String s, int maxLetters, int minSize, int maxSize) {
        Map<String, Integer> map = new HashMap<>();
        int ans = 0;
        for (int i = 0; i + minSize <= s.length(); i++) {
            for (int j = i + minSize; j <= i + maxSize && j <= s.length(); j++) {
                String t = s.substring(i, j);
                if (check(t, maxLetters)) {
                    map.put(t, map.getOrDefault(t, 0) + 1);
                    if (map.get(t) > ans) {
                        ans = map.get(t);
                    }
                }
            }
        }
        return ans;

    }
    public boolean check(String s, int maxLetters) {
        Set<Integer> set = new HashSet<>();
        for (int i = 0; i < s.length(); i++) {
            set.add(s.charAt(i) - 'a');
            if (set.size() > maxLetters) {
                return false;
            }
        }
        return true;
    }
}
